<?php
// 测试数据库查询的脚本

// 数据库配置
$host = '127.0.0.1';
$dbname = 'yingyang';
$username = 'root';
$password = 'root';
$charset = 'utf8mb4';

try {
    $dsn = "mysql:host=$host;dbname=$dbname;charset=$charset";
    $pdo = new PDO($dsn, $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 测试数据库查询 ===\n\n";
    
    // 查询未处理的菜品
    echo "查询未处理的菜品 (ai_called = 0):\n";
    $stmt = $pdo->query('SELECT id, name FROM fa_food_dish WHERE ai_called = 0 LIMIT 5');
    $dishes = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo "找到 " . count($dishes) . " 个未处理的菜品:\n";
    foreach ($dishes as $dish) {
        echo "  ID: {$dish['id']}, 名称: {$dish['name']}\n";
    }
    
    echo "\n=== 测试完成 ===\n";
    
} catch (Exception $e) {
    echo "执行失败: " . $e->getMessage() . "\n";
}
?>